package com.atguigu.yygh.controller;

import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.result.Result;
import com.atguigu.yygh.service.HospitalService;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author zr
 * @date 2021/12/13 19:05
 */
@Api(tags = "医院管理")
@RestController
@RequestMapping("/admin/hosp/hospital")
public class HospitalController {
    @Resource
    private HospitalService hospitalService;

    @ApiOperation(value = "条件查询带分页 医院列表")
    @PostMapping("list/{page}/{limit}")
    public Result pageListHosp(@ApiParam(name = "page", value = "当前页码", required = true)
                               @PathVariable Integer page,
                               @ApiParam(name = "limit", value = "每页记录数", required = true)
                               @PathVariable Integer limit,
                               @ApiParam(name = "hospitalQueryVo", value = "查询对象", required = false)
                               @RequestBody(required = false) HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> hospitalPage = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
        return Result.ok(hospitalPage);
    }

    @ApiOperation(value = "更新上线状态")
    @GetMapping("updateStatus/{id}/{status}")
    public Result updateStatus(@ApiParam(name = "id", value = "医院id", required = true)
                               @PathVariable String id,
                               @ApiParam(name = "status", value = "状态（0：未上线 1：已上线）", required = true)
                               @PathVariable Integer status) {
        hospitalService.updateStatus(id, status);
        return Result.ok();
    }

    @ApiOperation(value = "获取医院详情信息")
    @GetMapping("showHospDetail/{id}")
    public Result showHospDetail(@PathVariable String id) {
        Map<String, Object> resultMap = hospitalService.getHospById(id);
        return Result.ok(resultMap);
    }
}
